package com.content.view.Frame.Content
{
	import com.content.model.GlobalVarProxy;
	import com.content.model.LoadedAssets.ConfigProxy;
	import com.content.view.AppMediator;
	import com.content.view.Frame.CBar.CBarMediator;
	import com.content.view.Frame.InfoTape.InfoTape_Mediator;
	import com.content.view.Frame.MainPanel.*;
	import com.content.view.Frame.MainPanel.MPCapacity.MPCapacity_Mediator;
	import com.content.view.Frame.MainPanel.MPDebug.MPDebug_Mediator;
	import com.content.view.Frame.MainPanel.MPHome.MPHome_Mediator;
	import com.content.view.Frame.MainPanel.MPMyShelf.MPMyShelf_Mediator;
	import com.content.view.Frame.MainPanel.MPOnlineResAudio.MPOnlineResAudio_Mediator;
	import com.content.view.Frame.MainPanel.MPOnlineResBook.MPOnlineResBook_Mediator;
	import com.content.view.Frame.MainPanel.MPOnlineResVideo.MPOnlineResVideo_Mediator;
	import com.content.view.Frame.MainPanel.MPPassword.MPPassword_Mediator;
	import com.content.view.Frame.MainPanel.MPUserInfo.MPUserInfo_Mediator;
	import com.library.core.IDisposable;
	
	import flash.display.Sprite;
	import flash.events.DataEvent;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class ContentMediator extends Mediator implements IMediator, IDisposable
	{
		public static const NAME:String							= 'ContentWrapperMediator';
		
		private var _view:Content;
		
		public function ContentMediator(viewComponent:Object=null)
		{
			
			super( NAME, viewComponent );
		}
		
		override public function onRegister():void
		{
			_view = new Content();
			ParentView.addChild( _view );
			
			// 添加子面板
			facade.registerMediator( new MPPassword_Mediator( _view ) );
			facade.registerMediator( new MPCapacity_Mediator( _view ) );
			
			facade.registerMediator( new MPHome_Mediator( _view ) );
			facade.registerMediator( new MPOnlineResBook_Mediator( _view ) );
			facade.registerMediator( new MPOnlineResVideo_Mediator( _view ) );
			facade.registerMediator( new MPOnlineResAudio_Mediator( _view ) );
			facade.registerMediator( new MPMyShelf_Mediator( _view ) );
			facade.registerMediator( new MPUserInfo_Mediator( _view ) );
			
			if(P_Config.Debug)	facade.registerMediator( new MPDebug_Mediator( _view ) );
			
			facade.registerMediator( new CBarMediator( _view ) );
			facade.registerMediator( new InfoTape_Mediator( _view ) );
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				Content.SHOW,
				Content.HIDE,
				App.RESIZE_SYS
			];
		}
		
		/* Event Handler
		* ---------------------------------------------------- */
		override public function handleNotification(notification:INotification):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			
			switch ( name )
			{
				case Content.SHOW:
					_view.Show(body["delay"], body["duration"]);			
					break;
				
				case Content.HIDE:
					_view.Hide();			
					break;
				
				case App.RESIZE_SYS:
					var sWidth:int = body["width"];
					var sHeight:int = body["height"];
					_view.SetLayout(sWidth, sHeight);	// 重画最下面的蓝色布纹填充
					break;
			}
		}
		
		private function get ParentView():Sprite {return viewComponent as Sprite;}
		private function get P_Config():ConfigProxy	{return facade.retrieveProxy( ConfigProxy.NAME ) as ConfigProxy;}
		
		public function Dispose():void {
			_view.Dispose();
		}
	}
}